//
//  SYMyHomepageViewController.m
//  BSHOUYIFANG
//
//  Created by lanou3g on 15/8/21.
//  Copyright (c) 2015年 CYB. All rights reserved.
//

#import "SYMyHomepageViewController.h"
#import "Header.h"
#import "SYMyHomeHeaderView.h"
#import "SYFileHandle.h"
#import "SYMyFmdb.h"
@interface SYMyHomepageViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)UITableView *mainTV;
@end

@implementation SYMyHomepageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self navigationItemTitleColor];
    _mainTV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
    _mainTV.dataSource = self;
    _mainTV.delegate = self;
    [self.view addSubview:_mainTV];
    UIButton*leftButton = [[UIButton alloc]initWithFrame:CGRectMake(0,0,30*0.6,30*0.6)];
    [leftButton setImage:[UIImage imageNamed:@"iconfont-fanhui"]forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(searchprogram) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem*leftItem = [[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem= leftItem;
}
- (void)searchprogram{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)navigationItemTitleColor
{
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"我的主页"];
    customLab.textAlignment = NSTextAlignmentCenter;
    customLab.font = [UIFont boldSystemFontOfSize:20];
    self.navigationItem.titleView = customLab;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    return cell;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    SYMyHomeHeaderView *header = [[SYMyHomeHeaderView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, (SCREEN_HEIGHT - 64) * 2 / 5)];
    /**
     *  如果登陆成功 则使用登陆用户的用户名
     */
    
    BOOL islongin = [[SYFileHandle shareInstance] loginState];
    if (islongin) {
        NSString *str = [[SYFileHandle shareInstance] phoneNumber];
        SYUser *user = [[SYMyFmdb shareInstance]getUserInfophoneNumber:str];
        header.nameLabel.text = user.username;
        header.nameLabel.textColor = [UIColor blackColor];
        [header.iconButton setBackgroundImage:[UIImage imageWithData:user.icon] forState:UIControlStateNormal];
        UIImage *image = [UIImage imageWithData:user.icon];
        [header.iconButton setBackgroundImage:image forState:UIControlStateNormal];
    }

    return header;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return (SCREEN_HEIGHT - 64) * 2 / 5.0;
}

- (void)viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.translucent = NO;
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.tabBar.translucent = YES;
    self.tabBarController.tabBar.hidden = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
